<template>
  <div>
    <div style="height:60px;padding: 0 1.2rem;" class="row container">

      <router-link :to="{ path: '/', query: {}}" class="col-6 text-left">
        <img src="../../static/img/logo.png" alt="logo" style="width:70px;"><span class="small">登录页</span>
      </router-link>
      <div class="col-4">
      </div>
      <!-- <div class="col-6 text-right"  style="padding-top:20px;">
        <router-link :to="{ path: '/login', query: {}}"><button type="button" class="btn btn-light btn-sm">登录</button></router-link>
        <router-link :to="{ path: '/register', query: {}}"><button type="button" class="btn btn-light btn-sm">注册</button></router-link>
      </div> -->
    </div>
  <div class="container">
    <div class="row"  style="margin-top:100px;">
      <!-- <div class="col-xs-6 col-sm-3">.col-xs-6 .col-sm-3</div>
      <div class="col-xs-6 col-sm-3">.col-xs-6 .col-sm-3</div> -->
      <div class="col-12" style="margin-bottom:50px;">
        <div class="form-group text-left">
          <!-- <label for="exampleInputEmail1">已验证手机</label> -->
          <input type="text" class="form-control" id="exampleInputEmail1" placeholder="已验证手机" v-model="form.username">
          <!-- <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> -->
        </div>
        <div class="form-group text-left">
          <!-- <label for="exampleInputPassword1">密码</label> -->
          <input type="password" class="form-control" id="exampleInputPassword1" placeholder="密码" v-model="form.password">
        </div>
        <!-- <div class="form-check">
          <input type="checkbox" class="form-check-input" id="exampleCheck1">
          <label class="form-check-label" for="exampleCheck1">Check me out</label>
        </div> -->

        <div v-if="alert" class="alert alert-danger small" role="alert">
          {{msg}}
        </div>

        <br>
        <button @click="submit" class="btn btn-primary col-12">登录</button>
      </div>
        <p class="col-6 text-left small"><router-link :to="{ path: '/changepassword', query: {}}">忘记密码</router-link></p>
        <p class="col-6 text-right small"><router-link  style="color:#409eff" :to="{ path: '/register', query: {}}">立即注册</router-link></p>
    </div>


  </div>
  </div>

</template>

<script>
export default {
  data () {
    return {
      alert: false,
      msg: '',
      form: {"username":"","password":""}
    }
  },
  created() {

  },
  methods: {
    submit() {
        this.axios.post(`${this.config.baseURL}${this.config.port}/login`,this.form)
        .then((response) => {
            //  console.log('data', response.data)
              this.msg = response.data.message
              this.alert = true
              if (response.data.code === 200) {
                  localStorage.setItem('token', JSON.stringify(response.data.token));
                  localStorage.setItem('userinfo', JSON.stringify(response.data.res));
                  setTimeout(() => {
                    // console.log('id:', this.id);
                    this.$router.push({path:'/'})
                  }, 2000);
              }
            })
    },
  // 注册
  // getSite() {
  //   this.$axios.get('/website/siteList').then(({status,data})=>{
  //       if(status===200){
  //         if(data&&data.code === 1){
  //           console.log('this.middleList', data.data.favorite)
  //           this.middleList = data.data.favorite

  //           // setTimeout(()=>{
  //           //   this.$message.success('取出成功');
  //           // }, 2300)
  //         } else if(data&&data.code === 0) {
  //           this.middleList = data.data
  //         } else {
  //           // this.error=data.msg
  //           // this.$message.error(data.msg);
  //         }
  //       }else{
  //         this.error=`服务器出错`
  //       }
  //     })
  //   }
  }  
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  /* color: #42b983; */
  text-decoration:none;
}

.btn-primary {
    color: #fff;
    background-color: #409eff;
    border-color: #409eff;
}

</style>
